package de.chronicals.UnlimitedSlots;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.server.ServerListPingEvent;

public class UnlimitedSlotsListener
  implements Listener
{
  UnlimitedSlots plugin;
  
  public UnlimitedSlotsListener(UnlimitedSlots instance)
  {
    this.plugin = instance;
  }

  @EventHandler
  public void onServerListPing(ServerListPingEvent event) {
    event.setMaxPlayers(this.plugin.getConfig().getInt("Config.maxPlayers"));
  }

  @EventHandler(priority=EventPriority.HIGHEST)
  public void onPlayerLogin(PlayerLoginEvent event)
  {
    if ((this.plugin.getConfig().getInt("Config.maxPlayers") >= Bukkit.getServer().getOnlinePlayers().length) && (event.getResult().equals(PlayerLoginEvent.Result.KICK_FULL)))
      event.allow();
  }
}